package service

import (
	"context"
	"fmt"
	"video-srv/basic/config"
	__ "video-srv/basic/proto"
	"video-srv/handler/model"
)

type Server struct {
	__.UnimplementedVideoServer
}

// SayHello implements helloworld.GreeterServer
func (s *Server) VideoAdd(_ context.Context, in *__.VideoAddReq) (*__.VideoAddResp, error) {
	//参数校验
	if in.Title == "" || in.Duration == "" || in.ViUrl == "" || in.VideoType == "" {
		return nil, fmt.Errorf("视频参数不能为空")
	}

	video := model.Video{
		Title:     in.Title,
		Duration:  in.Duration,
		VideoType: in.VideoType,
		ViUrl:     in.ViUrl,
	}
	config.DB.Create(&video)
	return &__.VideoAddResp{
		VideoId: int64(video.ID),
	}, nil
}
